﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.IBLL;
using HZ.Supervise.Model;
using HZ.Supervise.Model.Enum;
using HZ.Supervise.Model.View;
using System.Data;
using HZ.Supervise;

public partial class TotalDrugs_Report6 : BasePage
{
    public TotalDrugs_Report6()
    {
        //this.ModuleNo = Module.医院统计分析.ToString();
        //this.PageOperateType = OperateType.地区汇总统计.ToString();
    }

    IBLL_User iu = BLLFactory.BLL_User();
    KeyOperationLogJG kj;
    IBLL_Company ic = HZ.Supervise.BLLFactory.IBLL_Company();
    HZ.Supervise.IBLL.IExecuteContext i = HZ.Supervise.BLLFactory.ExecuteContext();
    SuperviseQuery vs = new SuperviseQuery();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ddlArea.InitAreaID = CurrentAccount.GetUser().Org.Area.AreaID;
        }
    }

    /// <summary>
    /// 查询
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void AspNetPager_CompanyPS_PageChanged(object sender, EventArgs e)
    {
        BindData();
    }

    /// <summary>
    /// 绑定数据
    /// modify  by张雄  2011.5.4
    /// </summary>
    public void BindData()
    {
        string orderby = this.OrderFileds.SelectedValue + "  " + this.OrderType.SelectedValue;//排序字段与方式
        vs = Queryby();
        int t = 0;

        System.Data.DataTable dt = i.GetReport6(orderby, vs, this.AspNetPager_CompanyPS.CurrentPageIndex, AspNetPager_CompanyPS.PageSize, out t);

        AspNetPager_CompanyPS.RecordCount = t;

        this.gvwPSLInfo.PageSize = AspNetPager_CompanyPS.PageSize;
        this.gvwPSLInfo.DataSource = dt;
        this.gvwPSLInfo.DataBind();

        dt = i.GetReport6(orderby, vs, 1, 0, out t);
        double AJQCountTotal = 0;
        double AHalfCountTotal = 0;
        double ACountTotal = 0;
        double BJQCountTotal = 0;
        double BHalfCountTotal = 0;
        double BCountTotal = 0;

        double AJQshuTotal = 0;
        double AHalfshuTotal = 0;
        double AshuTotal = 0;
        double BJQshuTotal = 0;
        double BHalfshuTotal = 0;
        double BshuTotal = 0;
        for (int j = 0; j < dt.Rows.Count; j++)
        {
            AJQCountTotal += Convert.ToDouble(dt.Rows[j]["AJQCount"]);
            AHalfCountTotal += Convert.ToDouble(dt.Rows[j]["AHalfCount"]);
            ACountTotal += Convert.ToDouble(dt.Rows[j]["ACount"]);
            BJQCountTotal += Convert.ToDouble(dt.Rows[j]["BJQCount"]);
            BHalfCountTotal += Convert.ToDouble(dt.Rows[j]["BHalfCount"]);
            BCountTotal += Convert.ToDouble(dt.Rows[j]["BCount"]);

            AJQshuTotal += Convert.ToDouble(dt.Rows[j]["AJQshu"]);
            AHalfshuTotal += Convert.ToDouble(dt.Rows[j]["AHalfshu"]);
            AshuTotal += Convert.ToDouble(dt.Rows[j]["Ashu"]);
            BJQshuTotal += Convert.ToDouble(dt.Rows[j]["BJQshu"]);
            BHalfshuTotal += Convert.ToDouble(dt.Rows[j]["BHalfshu"]);
            BshuTotal += Convert.ToDouble(dt.Rows[j]["Bshu"]);
        }

        lblMemo.Text = "A月整改高于加权平均价产品数" + AJQCountTotal.ToString() + "个，涉及机构" + AJQshuTotal.ToString() + " 个； A月整改高于最低采购价50%产品数" + AHalfCountTotal.ToString() +
            "个 ，涉及机构" + AHalfshuTotal.ToString() + "个；A月整改产品总数" + ACountTotal.ToString() + "个，涉及机构" + AshuTotal.ToString() + " 个";
        lblMemo2.Text = "B月整改高于加权平均价产品数" + BJQCountTotal.ToString() + "个，涉及机构" + BJQshuTotal.ToString() + " 个； B月整改高于最低采购价50%产品数" + BHalfCountTotal.ToString() +
           "个 ，涉及机构" + BHalfshuTotal.ToString() + "个 ；B月整改产品总数" + BCountTotal.ToString() + "个，涉及机构" + BshuTotal.ToString() + " 个";
        AddLog(string.Format("查询异常采购产品预警数据!"));

        // Session[sessionId] = vs;
    }
    protected void btnQuery_Click(object sender, EventArgs e)
    {
        AspNetPager_CompanyPS.CurrentPageIndex = 1;
    }

    //protected void gvwInfo_RowCommand(object sender, GridViewCommandEventArgs e)
    //{
    //    Control cmdControl = e.CommandSource as Control;
    //    GridViewRow row = cmdControl.NamingContainer as GridViewRow;
    //    string str = row.Cells[1].Text;
    //    //if (e.CommandName == "lbnPrint")
    //    //{
    //    //    LinkButton lbnP = (LinkButton)row.FindControl("lbnPrint");
    //    //    string CompanyID_PS = lbnP.CommandArgument;
    //    //    ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='javascript'>window.open('../Secondphase/Print/PrintPaymentVoucher.aspx?CompanyID_PS=" + CompanyID_PS + "');</script>");
    //    //}

    //    if (str != "总计")
    //    {
    //        vs = Queryby();
    //        vs.BackPage = "area";
    //        string sessionId = Guid.NewGuid().ToString();
    //        vs.AreaID = e.CommandArgument.ToString().Split('|')[0];
    //        vs.AreaName = e.CommandArgument.ToString().Split('|')[1];
    //        Session[sessionId] = vs;

    //        if (e.CommandName == "lbnP")
    //        {
    //            Response.Redirect("../Enterprise/PurchaseAmountDetail.aspx?sesid=" + sessionId);

    //        }

    //        if (e.CommandName == "lbnD")
    //        {
    //            Response.Redirect("../Enterprise/DistributeAmountDetail.aspx?sesid=" + sessionId);
    //        }
    //        if (e.CommandName == "lbnW")
    //        {
    //            Response.Redirect("../Enterprise/WarehouseAmountDetail.aspx?sesid=" + sessionId);
    //        }
    //        if (e.CommandName == "lbnS")
    //        {
    //            Response.Redirect("../Enterprise/SellAmountDetail.aspx?sesid=" + sessionId);
    //        }
    //        if (e.CommandName == "lbnR")
    //        {
    //            Response.Redirect("../Enterprise/ReturnAmountDetail.aspx?sesid=" + sessionId);

    //        }
    //    }
    //}


    /// <summary>
    /// 分页    县区
    /// by张雄
    /// </summary>
    /// <param name="sender">事件发送源</param>
    /// <param name="e">事件参数</param>
    protected void CompanyPSL_PS_PageChanged(object sender, EventArgs e)
    {
        BindData();

    }



    /// <summary>
    /// 导出
    /// modify  by  张雄    2011.5.5
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnExcel_Click(object sender, EventArgs e)
    {
        string orderby = this.OrderFileds.SelectedValue + "  " + this.OrderType.SelectedValue;//排序字段与方式
        //SuperviseQuery vs = new SuperviseQuery();
        vs = Queryby();
        int t = 0;
        System.Data.DataTable dt = i.GetReport6(orderby, vs, 1, 0, out t);
        AddLog(string.Format("导出月报统计数据成功!"));
        ExportFile.Instance.ExportData(dt, gvwPSLInfo, this.Page);
    }



    /// <summary>
    /// 查询条件
    /// </summary>
    /// <returns></returns>
    private SuperviseQuery Queryby()
    {
        //SuperviseQuery vs = new SuperviseQuery();


        //时间
        string timeFrom = "1900-01-01 00:00:00";//起始时间
        string timeTo = "2444-12-30 23:59:59";//结束时间
        if (!string.IsNullOrEmpty(txtStratTime.Text))
        {

            vs.SubmiTimeFrom = Convert.ToDateTime(txtStratTime.Text.Trim());
        }
        else
        {
            vs.SubmiTimeFrom = Convert.ToDateTime(timeFrom);
        }
        if (!string.IsNullOrEmpty(txtEndTime.Text))
        {
            vs.SubmiTimeTo = Convert.ToDateTime(txtEndTime.Text.Trim()).AddDays(1);

        }
        else
        {
            vs.SubmiTimeTo = Convert.ToDateTime(timeTo);
        }
        if (vs.SubmiTimeFrom > vs.SubmiTimeTo)
        {
            HZ.Web.WebUtil.Alert("开始时间不能大于结束时间");
            vs.SubmiTimeFrom = Convert.ToDateTime(timeFrom);
            vs.SubmiTimeTo = Convert.ToDateTime(timeTo);
        }
        if (!string.IsNullOrEmpty(txtHospitalName.Text))
        {
            vs.HospitalName = txtHospitalName.Text.Trim();

        }

        vs.AreaID = ddlArea.SelectedAreaID;
        return vs;
    }

    protected void HzButton1_Click(object sender, EventArgs e)
    {
        string sesid = Guid.NewGuid().ToString();
        ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='javascript'>window.open('../Secondphase/Print/PrintPaymentVoucher.aspx?sesid=" + sesid + "');</script>");
    }
    /// <summary>
    /// 添加日志
    /// </summary>
    /// <param name="msg"></param>
    private void AddLog(string msg)
    {
        kj = new KeyOperationLogJG();
        kj.OperationLogSerialID = Guid.NewGuid().ToString();
        kj.Operator = CurrentAccount.GetUser().UserID;
        kj.OrgID = CurrentAccount.GetUser().Org.OrgID;
        kj.OperateTime = DateTime.Now;
        kj.OperateMessage = msg;
        iu.AddKeyOperationLog(kj);
    }

}
